package com.logos;

import com.logos.config.SpringConfig;
import com.logos.dao.AccountDao;
import com.logos.entity.Account;
import com.logos.service.AccountService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.io.IOException;
import java.io.InputStream;

public class AppForIntegrationMyBatis {
//    public static void main(String[] args) throws Exception {
//        SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
//        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
//        SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(inputStream);
//        SqlSession sqlSession = sqlSessionFactory.openSession();
//        AccountDao accountDao = sqlSession.getMapper(AccountDao.class);
//        Account account = accountDao.findById(2);
//        System.out.println("account = " + account);
//        sqlSession.close();
//    }

    public static void main(String[] args) {
        ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
        AccountService accountService = ctx.getBean(AccountService.class);
        Account account = accountService.selectById(1);
        System.out.println("account = " + account);
    }
}
